﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PMS.Client.Entities;
using PMS.Client.IBLL;
using PMS.Client.IDAL;
using PMS.Client.Utils;

namespace PMS.Client.BLL
{
    public class OrderService : ServiceBase, IOrderService
    {
        IOrderAccess _orderAccess;
        public OrderService(IOrderAccess orderAccess)
        {
            _orderAccess = orderAccess;
        }

        public int ChangeState(string id, int state)
        {
            string json = _orderAccess.ChangeState(id, state);
            return this.GetResult<int>(json);
        }

        public int DeleteOrder(string id)
        {
            string json = _orderAccess.DeleteOrder(id);
            return this.GetResult<int>(json);
        }

        public PageEntity<OrderEntity[]> GetOrderPage(string key, int index, int size)
        {
            string json = _orderAccess.GetOrders(key, index, size);
            return this.GetResult<PageEntity<OrderEntity[]>>(json);
        }

        public int UpdateOrder(OrderEntity entity)
        {
            string json = "";
            try
            {
                json = JsonUtil.Serializer(entity);
                json = _orderAccess.UpdateOrder(json);
                return this.GetResult<int>(json);
            }
            catch
            {
                throw new Exception("接口请求出错！" + json);
            };
        }
    }
}
